Tuesday, 11 April 2017


PROCEDURE IN PL/SQL TO PRINT 1-100 PRIME NUMBER OR YOU CAN CHANGE THE VALUE AS DESIRE FOR K

CREATE OR REPLACE PROCEDURE PRIME_NUM
DECLARE
M NUMBER(5);
N NUMBER(5);
K NUMBER(5);
BEGIN
M := 2;
N := 2;
K := 100;
LOOP
LOOP
EXIT WHEN MOD(M,N) = 0 OR M = N;
N := N + 1;
END LOOP;
IF M = N THEN
DBMS_OUTPUT.PUT_LINE ( M || 'IS PRIME');
END IF;
M := M + 1;
EXIT WHEN M > K;
END LOOP;
END;
END PROCEDURE;

Wednesday, 9 March 2016

Implementation of MD5 Algorithm in Java

Implementation of MD5 Algorithm in Java


java Program

  1. import java.math.BigInteger;
  2. import java.security.MessageDigest;
  3. import java.security.NoSuchAlgorithmException;
  4. public class JavaMD5Hash {
  5. public static void main(String[] args) {
  6. System.out.println("For null " + md5(""));
  7. System.out.println("For simple text "+ md5("This is my text"));
  8. System.out.println("For simple numbers " + md5("12345"));
  9. }
  10. public static String md5(String input) {
  11. String md5 = null;
  12. if(null == input) return null;
  13. try {
  14. //Create MessageDigest object for MD5
  15. MessageDigest digest = MessageDigest.getInstance("MD5");
  16. //Update input string in message digest
  17. digest.update(input.getBytes(), 0, input.length());
  18. //Converts message digest value in base 16 (hex)
  19. md5 = new BigInteger(1, digest.digest()).toString(16);
  20. }
  21. catch (NoSuchAlgorithmException e) {
  22. e.printStackTrace();
  23. }
  24. return md5;
  25. }
  26. }

Implementation of RSA Algorithm(Encryption and Decryption) in Java

Implementation of RSA Algorithm(Encryption and Decryption) in Java


JAVA Program

    1. import java.math.BigInteger;
    1. import java.util.Random;
    1. import java.io.*;
    1. public class RSA {
    1. private BigInteger p;
    1. private BigInteger q;
    1. private BigInteger N;
    1. private BigInteger phi;
    1. private BigInteger e;
    1. private BigInteger d;
    1. private int bitlength = 1024;
    1. private int blocksize = 256;
    1. //blocksize in byte
    1. private Random r;
    1. public RSA() {
    1. r = new Random();
    1. p = BigInteger.probablePrime(bitlength, r);
    1. q = BigInteger.probablePrime(bitlength, r);
    1. N = p.multiply(q);
    1. phi = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));
    1. e = BigInteger.probablePrime(bitlength/2, r);
    1. while (phi.gcd(e).compareTo(BigInteger.ONE) > 0 && e.compareTo(phi) < 0 ) {
    1. e.add(BigInteger.ONE);
    1. }
    1. d = e.modInverse(phi);
    1. }
    1. public RSA(BigInteger e, BigInteger d, BigInteger N) {
    1. this.e = e;
    1. this.d = d;
    1. this.N = N;
    1. }
    1. public static void main (String[] args) throws IOException {
    1. RSA rsa = new RSA();
    1. DataInputStream in=new DataInputStream(System.in);
    1. String teststring ;
    1. System.out.println("Enter the plain text:");
    1. teststring=in.readLine();
    1. System.out.println("Encrypting String: " + teststring);
    1. System.out.println("String in Bytes: " + bytesToString(teststring.getBytes()));
    1. // encrypt
    1. byte[] encrypted = rsa.encrypt(teststring.getBytes());
    1. System.out.println("Encrypted String in Bytes: " + bytesToString(encrypted));
    1. // decrypt
    1. byte[] decrypted = rsa.decrypt(encrypted);
    1. System.out.println("Decrypted String in Bytes: " + bytesToString(decrypted));
    1. System.out.println("Decrypted String: " + new String(decrypted));
    1. }
    1. private static String bytesToString(byte[] encrypted) {
    1. String test = "";
    1. for (byte b : encrypted) {
    1. test += Byte.toString(b);
    1. }
    1. return test;
    1. }
    1. //Encrypt message
    1. public byte[] encrypt(byte[] message) {
    1. return (new BigInteger(message)).modPow(e, N).toByteArray();
    1. }
    1. // Decrypt message
    1. public byte[] decrypt(byte[] message) {
    1. return (new BigInteger(message)).modPow(d, N).toByteArray();
    1. }
    1. }

Wednesday, 18 September 2013

Assignment 4 for print of vb.net

Assignmebnt No. – 04
 
Program on Innterface :-
 
Module IntefaceExamplekb
 
    Sub Main()
        Dim obj As New Class2
        obj.add()
        obj.pro()
        Console.ReadLine()
    End Sub
 
End Module
 
 
Interface in1
    Sub add()
End Interface
 
Interface in2
    Sub pro()
End Interface
 
Interface in3
    Inherits in1, in2
End Interface
 
 
Public Class Class2 : Implements in3
 
    Public Sub add() Implements in1.add
        Console.WriteLine("Add Function...")
    End Sub
 
    Public Sub pro() Implements in2.pro
        Console.WriteLine("Product Function...")
    End Sub
End Class
 
 
Output :-
 


Program on Exception Handling :-
 
Module ExecptionHandlingExamplekb
 
    Sub Main()
        Dim a, b, c As Integer
        Console.Write("Enter a and b :")
        a = CInt(Console.ReadLine)
        b = CInt(Console.ReadLine)
        Console.WriteLine("a = " + a.ToString())
        Console.WriteLine("b = " + b.ToString())
        Console.WriteLine()
        Try
            c = a \ b
            Console.WriteLine("c = " + c.ToString())
        Catch ex As Exception
            Console.WriteLine("Exception occured: " + ex.Message())
        End Try
        Console.ReadLine()
    End Sub
 
End Module
 
Output :-